home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / lib / perl / 5.10.1 / re.pm < prev    next >
Encoding:
Perl POD Document  |  2012-12-11  |  5.1 KB  |  183 lines

  1. package re;
  2.  
  3. # pragma for controlling the regex engine
  4. use strict;
  5. use warnings;
  6.  
  7. our $VERSION     = "0.09";
  8. our @ISA         = qw(Exporter);
  9. my @XS_FUNCTIONS = qw(regmust);
  10. my %XS_FUNCTIONS = map { $_ => 1 } @XS_FUNCTIONS;
  11. our @EXPORT_OK   = (@XS_FUNCTIONS,
  12.                     qw(is_regexp regexp_pattern
  13.                        regname regnames regnames_count));
  14. our %EXPORT_OK = map { $_ => 1 } @EXPORT_OK;
  15.  
  16. # *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
  17. #
  18. # If you modify these values see comment below!
  19.  
  20. my %bitmask = (
  21.     taint   => 0x00100000, # HINT_RE_TAINT
  22.     eval    => 0x00200000, # HINT_RE_EVAL
  23. );
  24.  
  25. # - File::Basename contains a literal for 'taint' as a fallback.  If
  26. # taint is changed here, File::Basename must be updated as well.
  27. #
  28. # - ExtUtils::ParseXS uses a hardcoded 
  29. # BEGIN { $^H |= 0x00200000 } 
  30. # in it to allow re.xs to be built. So if 'eval' is changed here then
  31. # ExtUtils::ParseXS must be changed as well.
  32. #
  33. # *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
  34.  
  35. sub setcolor {
  36.  eval {                # Ignore errors
  37.   require Term::Cap;
  38.  
  39.   my $terminal = Tgetent Term::Cap ({OSPEED => 9600}); # Avoid warning.
  40.   my $props = $ENV{PERL_RE_TC} || 'md,me,so,se,us,ue';
  41.   my @props = split /,/, $props;
  42.   my $colors = join "\t", map {$terminal->Tputs($_,1)} @props;
  43.  
  44.   $colors =~ s/\0//g;
  45.   $ENV{PERL_RE_COLORS} = $colors;
  46.  };
  47.  if ($@) {
  48.     $ENV{PERL_RE_COLORS} ||= qq'\t\t> <\t> <\t\t';
  49.  }
  50.  
  51. }
  52.  
  53. my %flags = (
  54.     COMPILE         => 0x0000FF,
  55.     PARSE           => 0x000001,
  56.     OPTIMISE        => 0x000002,
  57.     TRIEC           => 0x000004,
  58.     DUMP            => 0x000008,
  59.     FLAGS           => 0x000010,
  60.  
  61.     EXECUTE         => 0x00FF00,
  62.     INTUIT          => 0x000100,
  63.     MATCH           => 0x000200,
  64.     TRIEE           => 0x000400,
  65.  
  66.     EXTRA           => 0xFF0000,
  67.     TRIEM           => 0x010000,
  68.     OFFSETS         => 0x020000,
  69.     OFFSETSDBG      => 0x040000,
  70.     STATE           => 0x080000,
  71.     OPTIMISEM       => 0x100000,
  72.     STACK           => 0x280000,
  73.     BUFFERS         => 0x400000,
  74. );
  75. $flags{ALL} = -1 & ~($flags{OFFSETS}|$flags{OFFSETSDBG}|$flags{BUFFERS});
  76. $flags{All} = $flags{all} = $flags{DUMP} | $flags{EXECUTE};
  77. $flags{Extra} = $flags{EXECUTE} | $flags{COMPILE};
  78. $flags{More} = $flags{MORE} = $flags{All} | $flags{TRIEC} | $flags{TRIEM} | $flags{STATE};
  79. $flags{State} = $flags{DUMP} | $flags{EXECUTE} | $flags{STATE};
  80. $flags{TRIE} = $flags{DUMP} | $flags{EXECUTE} | $flags{TRIEC};
  81.  
  82. my $installed;
  83. my $installed_error;
  84.  
  85. sub _do_install {
  86.     if ( ! defined($installed) ) {
  87.         require XSLoader;
  88.         $installed = eval { XSLoader::load('re', $VERSION) } || 0;
  89.         $installed_error = $@;
  90.     }
  91. }
  92.  
  93. sub _load_unload {
  94.     my ($on)= @_;
  95.     if ($on) {
  96.         _do_install();        
  97.         if ( ! $installed ) {
  98.             die "'re' not installed!? ($installed_error)";
  99.     } else {
  100.         # We call install() every time, as if we didn't, we wouldn't
  101.         # "see" any changes to the color environment var since
  102.         # the last time it was called.
  103.  
  104.         # install() returns an integer, which if casted properly
  105.         # in C resolves to a structure containing the regex
  106.         # hooks. Setting it to a random integer will guarantee
  107.         # segfaults.
  108.         $^H{regcomp} = install();
  109.         }
  110.     } else {
  111.         delete $^H{regcomp};
  112.     }
  113. }
  114.  
  115. sub bits {
  116.     my $on = shift;
  117.     my $bits = 0;
  118.     unless (@_) {
  119.     require Carp;
  120.     Carp::carp("Useless use of \"re\" pragma"); 
  121.     }
  122.     foreach my $idx (0..$#_){
  123.         my $s=$_[$idx];
  124.         if ($s eq 'Debug' or $s eq 'Debugcolor') {
  125.             setcolor() if $s =~/color/i;
  126.             ${^RE_DEBUG_FLAGS} = 0 unless defined ${^RE_DEBUG_FLAGS};
  127.             for my $idx ($idx+1..$#_) {
  128.                 if ($flags{$_[$idx]}) {
  129.                     if ($on) {
  130.                         ${^RE_DEBUG_FLAGS} |= $flags{$_[$idx]};
  131.                     } else {
  132.                         ${^RE_DEBUG_FLAGS} &= ~ $flags{$_[$idx]};
  133.                     }
  134.                 } else {
  135.                     require Carp;
  136.                     Carp::carp("Unknown \"re\" Debug flag '$_[$idx]', possible flags: ",
  137.                                join(", ",sort keys %flags ) );
  138.                 }
  139.             }
  140.             _load_unload($on ? 1 : ${^RE_DEBUG_FLAGS});
  141.             last;
  142.         } elsif ($s eq 'debug' or $s eq 'debugcolor') {
  143.         setcolor() if $s =~/color/i;
  144.         _load_unload($on);
  145.         last;
  146.         } elsif (exists $bitmask{$s}) {
  147.         $bits |= $bitmask{$s};
  148.         } elsif ($XS_FUNCTIONS{$s}) {
  149.             _do_install();
  150.             if (! $installed) {
  151.                 require Carp;
  152.                 Carp::croak("\"re\" function '$s' not available");
  153.             }
  154.             require Exporter;
  155.             re->export_to_level(2, 're', $s);
  156.     } elsif ($EXPORT_OK{$s}) {
  157.         require Exporter;
  158.         re->export_to_level(2, 're', $s);
  159.     } else {
  160.         require Carp;
  161.         Carp::carp("Unknown \"re\" subpragma '$s' (known ones are: ",
  162.                        join(', ', map {qq('$_')} 'debug', 'debugcolor', sort keys %bitmask),
  163.                        ")");
  164.     }
  165.     }
  166.     $bits;
  167. }
  168.  
  169. sub import {
  170.     shift;
  171.     $^H |= bits(1, @_);
  172. }
  173.  
  174. sub unimport {
  175.     shift;
  176.     $^H &= ~ bits(0, @_);
  177. }
  178.  
  179. 1;
  180.  
  181. __END__
  182.  
  183.